//
//  ContainerViewController.m
//  UI豆瓣2
//
//  Created by dllo on 15/11/6.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "ContainerViewController.h"
#import "MovieCollectionViewController.h"
#import "MovieListViewController.h"
@interface ContainerViewController ()

@property (nonatomic, assign)BOOL isSelected;
@property (nonatomic, retain)MovieCollectionViewController *movieCollectionVC;
@property (nonatomic, retain)MovieListViewController *movieListVC;

@end

@implementation ContainerViewController

- (void)dealloc
{
    [_movieCollectionVC release];
    [_movieListVC release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor redColor];
    UIImage *rightImage = [UIImage imageNamed:@"btn_nav_collection@2x.png"];
    rightImage = [rightImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithImage:rightImage style:UIBarButtonItemStylePlain target:self action:@selector(rightAction:)] autorelease];
    self.isSelected = NO;
    
    self.movieCollectionVC = [[MovieCollectionViewController alloc] init];
    [self addChildViewController:self.movieCollectionVC];
    [self.view addSubview:self.movieCollectionVC.view];
    [_movieCollectionVC release];
    
    self.movieListVC = [[MovieListViewController alloc] init];
    [self addChildViewController:self.movieListVC];
    [self.view addSubview:self.movieListVC.view];
    [_movieListVC release];
    
    self.navigationItem.title = @"电影";
}

- (void)rightAction:(UIBarButtonItem *)btn{
    if (self.isSelected == NO) {
        [UIView transitionFromView:self.movieListVC.view toView:self.movieCollectionVC.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromRight completion:^(BOOL finished) {
            
        }];
        
        UIImage *rightImage = [UIImage imageNamed:@"btn_nav_list@2x.png"];
        rightImage = [rightImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithImage:rightImage style:UIBarButtonItemStylePlain target:self action:@selector(rightAction:)] autorelease];
        
    }else{
        [self.view bringSubviewToFront:self.movieCollectionVC.view];
        [UIView transitionFromView:self.movieCollectionVC.view toView:self.movieListVC.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromRight completion:^(BOOL finished) {
            
        }];
        
        UIImage *rightImage = [UIImage imageNamed:@"btn_nav_collection@2x.png"];
        rightImage = [rightImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithImage:rightImage style:UIBarButtonItemStylePlain target:self action:@selector(rightAction:)] autorelease];
    }
    self.isSelected = !self.isSelected;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
